package netty.c2;

import io.netty.channel.EventLoop;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;

public class TestNettyFuture {
    static Logger logger = LogManager.getLogger("mylog");
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        NioEventLoopGroup group = new NioEventLoopGroup();
        EventLoop eventLoop = group.next();
        Future<Integer> future = eventLoop.submit(new Callable<Integer>() {

            @Override
            public Integer call() throws Exception {
                logger.debug("执行计算");
                Thread.sleep(1000);
                return 70;
            }
        });
      //  logger.debug("等待结果");
      //  logger.debug("结果是{}", future.get());
        future.addListener(new GenericFutureListener<Future<? super Integer>>() {

            @Override
            public void operationComplete(Future<? super Integer> future) throws Exception {
                logger.debug("结果是{}", future.get());
            }
        });
    }
}
